<?php
/**
 * Created by PhpStorm.
 * User: Ellon_Wong
 * Date: 14-5-1
 * Time: 下午4:29
 */

include_once dirname(__FILE__) . '/../common/dbConn.php';
//include_once dirname(__FILE__) . '/../common/constant.php';

function login_func($arg_body){
    try{
        session_start();
        global $log;
        global $msgArray;
//        $log->info("===================register_func begin=====================");
//        $log->info("传入参数：");
//        $log->info($arg_body);
        if(!array_key_exists("userAccount",$arg_body)){
            return MsgArray(false,"传入用户名为空",[],"Warn");
        }

        if(!array_key_exists("userPassword",$arg_body)){
            return MsgArray(false,"传入密码为空",[],"Warn");
        }

        $rsl = MsgArray(false,"操作失败!",[],"Warn");

        $q_pdo=connectDatabase();
        if(null==$q_pdo){
            return MsgArray(false,"数据库连接异常",[],"Warn");
        }

        $req_ckSql = "SELECT ID FROM T_USER WHERE U_ACCOUNT = '".$arg_body["userAccount"]."' AND U_PASSWORD='".$arg_body["userPassword"]."'";
        $rs = $q_pdo->prepare($req_ckSql);
        $rs->execute();
        $rsl = $rs->fetch();
        if(false==$rsl){
            return MsgArray(false,"账号密码错误！","","Error");
        }

        $_SESSION["userId"] = $rsl["ID"];
        $_SESSION["userAccount"] = $arg_body["userAccount"];


        return MsgArray(true,"登录成功",$rsl,"Success");

    }catch (Exception $e){
        $log->error("抛出异常:".$e->getMessage());
        return MsgArray(100001,"系统异常",[],"Error");
    }
}